package com.budwk.app.sqfwV2.generator.oneFive.pdf;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.BusinessParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CompleteFlowBusinessParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.PdfGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BasePdfGenerator;
import com.budwk.app.sqfwV2.component.ProblemComponent;
import com.budwk.app.sqfwV2.dto.dto.OneFivePdfDTO;
import com.budwk.app.sqfwV2.enums.FileServiceConfigEnum;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.deepoove.poi.data.PictureRenderData;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * @author 垃圾分类
 */
public class OneFiveDocGenerator extends BasePdfGenerator{

    @Override
    public boolean pdfCreateConditionCheck(PdfGenerateParam pdfGenerateParam) {
        return true;
    }

    @Override
    public String getTemplatePath(PdfGenerateParam pdfGenerateParam) {
        return FileServiceConfigEnum.OOA.getFilePath();
    }

    @Override
    public void customerPopularPdfParam(Map<String, Object> paramMap, PdfGenerateParam pdfGenerateParam) {
        // 在这里对一些数据进行填充 进行复杂的业务代码逻辑
        OneFivePdfDTO pdfDTO = ProblemComponent.getPdfDTO(pdfGenerateParam.getAbstractCustomerPdfCreateField());
        // 巡查时间
        BusinessParam businessParam = pdfGenerateParam.getBusinessParam();
        Sqfw_formSummary_new formSummary = null;
        if (businessParam != null) {
            formSummary = ((CompleteFlowBusinessParam) pdfGenerateParam.getBusinessParam()).getFormSummary();
        }
        paramMap.put("fillDate", LocalDateTimeUtil.format(pdfDTO.getFillDate(), DatePattern.CHINESE_DATE_PATTERN));
        paramMap.put("disposalDate", LocalDateTimeUtil.format(pdfDTO.getDisposalDate(), DatePattern.CHINESE_DATE_TIME_PATTERN)); // 处置时间
        paramMap.put("area", formSummary != null ? formSummary.getDetailAddress() : null);
        String sitePhotos = pdfDTO.getSitePhotos();
        if (StringUtils.isNotEmpty(sitePhotos)) {
            paramMap.put("siteImagesStr", "附件");
            List<String> sitePhotosList = List.of(sitePhotos.split(","));
            List<Map<String, PictureRenderData>> pictures = CommonFormOfficeUtils.addWordPicture(sitePhotosList, "images", 15F, 12.5F);
            paramMap.put("imagess", pictures);
        } else {
            paramMap.put("siteImagesStr", "");
            paramMap.put("imagess", null);
        }
    }
}









